package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.extension.api.R;
import com.heima.model.admin.dots.ChannelDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2023/3/16 10:49
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;

    @GetMapping("/channels")
    public ResponseResult listAll() {
        return wmChannelService.findAll();
    }

    /**
     * 频道名称模糊分页查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public PageResponseResult channelPage(@RequestBody ChannelDto dto) {
        return wmChannelService.channelPage(dto);
    }

    /**
     * 新增频道
     */
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody WmChannel channel) {
        return wmChannelService.saveChannel(channel);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id) {
        return wmChannelService.deleteById(id);
    }

    /**
     * 修改频道
     * @param channel
     * @return
     */
    @PostMapping("/update")
    public ResponseResult updateChannel(@RequestBody WmChannel channel){
        return wmChannelService.updateChannel(channel);
    }

}